/*
* name;
*/
class GYScaleSprite extends GYSprite{
    private _mode:number;    
    private _invalidDraw:boolean;
    private $texture:Laya.Texture;
    private _clipPoint:Laya.Point;
    constructor(){
        super();
        let s= this;
        s._mode = ScaleMode.SCALE;
        s._clipPoint = new Laya.Point(0,0);
    }
    public set mode(val:number)
    {
        let s= this;
        s._mode = val;
        s._invalidDraw = true;
        LayoutManager.addRenderFunc(s);
    }
    public get mode():number
    {
        return this._mode;
    }
    public set clipX(val:number)
    {
        let s= this;
        s._clipPoint.x = -val;
        s._invalidDraw = true;
        LayoutManager.addRenderFunc(s);
    }
    public get clipX():number
    {
        return -this._clipPoint.x;
    }
    public set clipY(val:number)
    {
        let s= this;
        s._clipPoint.y = -val;
        s._invalidDraw = true;
        LayoutManager.addRenderFunc(s);
    }
    public get clipY():number
    {
        return -this._clipPoint.y;    
    }
    /**@ts-ignore*/
    public set width(val:number)
    {
        let s = this;
        Laya.superSet(GYSprite,s, "width", val);
        s._invalidDraw = true;
        LayoutManager.addRenderFunc(s);
    }
    /**@ts-ignore*/
    public get width():number
    {        
        return Laya.superGet(GYSprite,this, "width");
    }
    /**@ts-ignore*/
    public set height(val:number)
    {
        let s = this;
        Laya.superSet(GYSprite,s, "height", val);
        s._invalidDraw = true;
        LayoutManager.addRenderFunc(s);
    }
    /**@ts-ignore*/
    public get height():number
    {                
        return Laya.superGet(GYSprite,this, "height");
    }
    public set bitmapData(val:Laya.Texture)
    {
        let s= this;
        s.$texture = val;
        s.width = s.$texture?s.$texture.sourceWidth:0;
        s.height = s.$texture?s.$texture.sourceHeight:0;
        s._invalidDraw = true;
        LayoutManager.addRenderFunc(s);
    }
    public get bitmapData():Laya.Texture
    {
        return this.$texture;
    }
    public validDraw():void
    {
        let s= this;                
        s.graphics.clear();
        if(s.$texture == null)return;
        
        if(s._mode == ScaleMode.SCALE)
        {
            s.graphics.drawTexture(s.$texture,0, 0,s.width,s.height);
        }
        else
        {
            s.graphics.fillTexture(s.$texture,0,0,s.width,s.height,"no-repeat",s._clipPoint)
        }
    }
    public updateView():void
    {
        let s= this;
        if(s._invalidDraw)
        {
            s.validDraw();
            s._invalidDraw = false;
        }
    }
}